package com.baichang.taoshunda.dao.impl;

import com.baichang.taoshunda.dao.GoodsTypeDao;
import com.baichang.taoshunda.entity.GoodsType;
import com.baichang.framework.dao.impl.BaseDaoImpl;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class GoodsTypeDaoImpl extends BaseDaoImpl<GoodsType> implements GoodsTypeDao {
    /**
     * 查询商品类型
     *
     * @param type
     * @return
     */
    @Override
    public List<Map<String, Object>> queryGoodsType(Integer type) {
        String sql = "SELECT * FROM t_goods_type  WHERE company_id=?";
//        String sql = "SELECT * FROM t_goods_type gt LEFT JOIN t_company tc ON gt.company_id=tc.id WHERE tc.style=?";
        return queryForMapList(sql, type);
    }

    /**
     * 查询商家的商品类型
     *
     * @param companyId
     * @return
     */
    @Override
    public List<Map<String, Object>> findCompanyGoodsType(Integer companyId) {
        String sql = "SELECT gt.id, gt.`name` AS typeName, gt.company_id AS busId, gt.order_num FROM t_goods_type gt WHERE gt.company_id = ? ORDER BY gt.order_num ASC  ";
        return queryForMapList(sql, companyId);
    }

    @Override
    public boolean updateGoodsType(Integer id, String name, Integer orderNumber) {
        String sql = "UPDATE t_goods_type SET name=?, order_num=? WHERE id=?";
        return update(sql, name, orderNumber, id) > 0;
    }

    /**
     * 修改商品分类排序
     *
     * @param typeId
     * @param orderNumber
     * @return
     */
    @Override
    public int updateGoodsTypeOrderNumber(Integer typeId, Integer orderNumber) {
        String sql = " UPDATE {table} SET order_num=? WHERE id=? ";
        return update(sql, orderNumber, typeId);
    }
    /**
     * 查询商品分类
     *
     * @return
     */
    @Override
    public List<Map<String, Object>> queryStateGoodsType() {
        String sql = "SELECT * FROM {table}";
        return queryForMapList(sql);
    }
}

